package com.sunfeng.chap2.p17;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

/**
 * @Author : 孙峰
 * @Description:
 * @Date : 2021/10/11  9:43
 */
public class FileLockAPI_3 {
    public static void main(String[] args) throws IOException {
        File file = new File("d:\\nio\\a.txt");
        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
        FileChannel channel = randomAccessFile.getChannel();
        FileLock fileLock = channel.lock(1, 10, true);
        System.out.println(fileLock.overlaps(11,20)); //false
        fileLock.close();
    }
}
